from domain.domain import Catalog


# 需要新增\删除\修改\查询:返回所有的,返回指定id的,返回指定名称的
class CatalogDAO():

    def getAll(self, session):
        list = session.query(Catalog)
        return list

    def getById(self, session,id):
        list = session.query(Catalog).filter(Catalog.id == id).one()
        return list

    def update(self, session, catalog):
        # newCatalog=session.query(Catalog).filter(Catalog.id==catalog.id).one()
        # newCatalog=catalog
        # 更新fullname

        session.commit()
        return "success"

    # 根据名字返回对应的对象

    def getByName(self, session, name):
        list = session.query(Catalog).filter(Catalog.name == name).all()
        return list

        # 根据名字返回对应的对象

    def deleteById(self, session, id):
        list = session.query(Catalog).filter(Catalog.id == id).delete()
        return "success"

    def add(self,session,catalog):
        session.add(catalog)
        session.commit()
        return "success"



